import { resolve } from "path";
import { cwd } from "process";
import { CONFIG } from "./config";
import fs from "fs-extra";

/* join临时文件绝对路径 */
export const resolveTempFile = (...paths: string[]) => {
    return resolveWorkspace(CONFIG.TEMP_FILE_NAME, ...paths);
};
/* 工作区文件绝对路径 */
export const resolveWorkspace = (...paths: string[]) => {
    return resolve(cwd(), ...paths);
};
/* 创建临时文件目录 */
export const createTempFileDir = () => {
    const tempFileDir = resolveTempFile();
    if (!fs.existsSync(tempFileDir)) {
        fs.mkdirSync(tempFileDir);
    }
};
/* 删除临时文件 */
export const deleteTempFiles = () => {
    const tempFileDir = resolveTempFile();
    fs.emptyDirSync(tempFileDir);
};
/* 标准化目标系统路径 */
export const normalizePath = (path: string) => {
    return path.replace(/\\/g, "/");
};
